package com.xuetang9.fujian.net.reponse;

import com.xuetang9.fujian.model.User;
import com.xuetang9.fujian.net.client.Client;
import com.xuetang9.fujian.view.LoginFrame;
import com.xuetang9.fujian.view.MainFrame;
import com.xuetang9.fujian.view.WindowManager;

import javax.swing.*;
import java.util.HashMap;

/**
 * @describe:
 * @author:fujian
 * @date:2021/6/13
 * @Version: V1.0
 * @Package: com.xuetang9.fujian.net.reponse
 */
@SuppressWarnings("all")
public class LoginResponseHandler extends AbstractResponseHandler{
    @Override
    public void handleRequest(HashMap<String, Object> message, Client client) {
        boolean success = (boolean) message.get("success");
        if (success){
            // success
            User loginUser = (User) message.get("loginUser");
            WindowManager.getLoginFrame().dispose();
            WindowManager.addLoginFrame(null);
            WindowManager.addMainFrame(new MainFrame(loginUser));
        }else {
            LoginFrame loginFrame = WindowManager.getLoginFrame();
            JOptionPane.showMessageDialog(loginFrame,"请检查您的账户和密码","错误信息",JOptionPane.INFORMATION_MESSAGE);
        }
    }
}
